package com.link.base.base.guidepick.controller;

import com.link.base.base.guidepick.model.*;
import com.link.base.base.guidepick.model.*;
import com.link.base.base.guidepick.service.GuidePickService;
import com.link.core.cllog.LCLogger;
import com.link.core.basic.annotations.JsonParam;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Copyright  hande Company. All Rights Reserved.
 *
 * @author  unknwon
 * @date:   2018/11/12 10:27
 * @version 1.0
 */

@Controller
@RequestMapping("link/GuidePick")
public class GuidePickController {
    @Resource
    private GuidePickService qidianPickService;

    /**
     * 查询导购
     * @param session
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/queryGuide", method = RequestMethod.GET)
    @ResponseBody
    public Map<String, Object> queryEmp(HttpSession session, HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> result = new HashMap<String, Object>(4);
        int count = 0;
        // 当前记录总数
        int currentCount = Integer.parseInt(request.getParameter("currentCount"));
        String searchText = request.getParameter("searchText");
        GuideEmployee o = new GuideEmployee();
        o.setSearchText(searchText);
        try {
            if (currentCount == 0) {
                count = qidianPickService.queryEmpCount(o);
            }
            o.setStartRow(currentCount + 1);
            o.setEndRow(currentCount + o.getRows());

            List<GuideEmployee> list = qidianPickService.queryEmpList(o);
            result.put("count", count);
            result.put("success", true);
            result.put("result", list);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("message", e.getMessage());
        }
        return result;
    }

    /**
     * 查询客户
     *
     * @author song
     */
    @RequestMapping(value = "/queryAccount", method = RequestMethod.GET)
    @ResponseBody
    public Map<String, Object> queryAccount(HttpSession session, HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> result = new HashMap<String, Object>(4);
        int count = 0;
        // 当前记录总数
        int currentCount = Integer.parseInt(request.getParameter("currentCount"));
        String searchText = request.getParameter("searchText");
        GuidePickAccount o = new GuidePickAccount();
        o.setSearchText(searchText);
        try {
            if (currentCount == 0) {
                count = qidianPickService.queryAccountCount(o);
            }
            o.setStartRow(currentCount + 1);
            o.setEndRow(currentCount + o.getRows());

            List<GuidePickAccount> list = qidianPickService.queryAccountList(o);
            result.put("count", count);
            result.put("success", true);
            result.put("result", list);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("message", e.getMessage());
        }
        return result;
    }

    /**
     * 查询商机
     *
     * @author song
     */
    @RequestMapping(value = "/queryOpty", method = RequestMethod.GET)
    @ResponseBody
    public Map<String, Object> queryOpty(HttpSession session, HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> result = new HashMap<String, Object>(4);
        int count = 0;
        // 当前记录总数
        int currentCount = Integer.parseInt(request.getParameter("currentCount"));
        String searchText = request.getParameter("searchText");
        GuidePickOpty o = new GuidePickOpty();
        o.setSearchText(searchText);
        try {
            if (currentCount == 0) {
                count = qidianPickService.queryOptyCount(o);
            }
            o.setStartRow(currentCount + 1);
            o.setEndRow(currentCount + o.getRows());

            List<GuidePickOpty> list = qidianPickService.queryOptyList(o);
            result.put("count", count);
            result.put("success", true);
            result.put("result", list);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("message", e.getMessage());
        }
        return result;
    }

    /**
     * 查询客户地址
     *
     * @author song
     */
    @RequestMapping(value = "/queryReceiptAddr", method = RequestMethod.GET)
    @ResponseBody
    public Map<String, Object> queryReceiptAddr(HttpSession session, HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> result = new HashMap<String, Object>(4);
        int count = 0;
        // 当前记录总数
        int currentCount = Integer.parseInt(request.getParameter("currentCount"));
        String searchText = request.getParameter("searchText");
        Long acctId = Long.parseLong(request.getParameter("acctId"));
        GuidePickReceiptAddr o = new GuidePickReceiptAddr();
        o.setSearchText(searchText);
        o.setAcctId(acctId);
        try {
            if (currentCount == 0) {
                count = qidianPickService.queryaccntAddrCount(o);
            }
            o.setStartRow(currentCount + 1);
            o.setEndRow(currentCount + o.getRows());

            List<GuidePickReceiptAddr> list = qidianPickService.queryaccntAddrList(o);
            result.put("count", count);
            result.put("success", true);
            result.put("result", list);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("message", e.getMessage());
        }
        return result;
    }

    /**
     * 查询组织
     *
     * @author ying
     */
    @RequestMapping(value = "/queryOrgList", method = RequestMethod.GET)
    @ResponseBody
    public Map<String, Object> queryOrgList(@JsonParam GuidePickOrg record, HttpSession session,
                                            HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> result = new HashMap<String, Object>(4);
        try {
            List<GuidePickOrg> list = qidianPickService.queryOrgList(record);
            result.put("success", true);
            result.put("result", list);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            LCLogger.withException(e);
            result.put("success", false);
            result.put("result", e.getMessage());
        }
        return result;
    }
}
